package com.cloudweb.oa.service.impl;

import cn.js.fan.web.Global;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cloudweb.oa.entity.Role;
import com.cloudweb.oa.entity.UserRoleKind;
import com.cloudweb.oa.mapper.UserRoleKindMapper;
import com.cloudweb.oa.service.IUserRoleKindService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fgf
 * @since 2025-01-30
 */
@Service
public class UserRoleKindServiceImpl extends ServiceImpl<UserRoleKindMapper, UserRoleKind> implements IUserRoleKindService {

    @Autowired
    UserRoleKindMapper userRoleKindMapper;

    @Autowired
    IUserRoleKindService userRoleKindService;

    @Override
    public List<UserRoleKind> listByUnitCode(String unitCode) {
        QueryWrapper<UserRoleKind> qw = new QueryWrapper<>();
        qw.eq("unit_code", unitCode);
        qw.orderByAsc("orders");
        return userRoleKindMapper.selectList(qw);
    }

    @Override
    public int getMaxOrder(String unitCode) {
        QueryWrapper<UserRoleKind> qw = new QueryWrapper<>();
        qw.eq("unit_code", unitCode);
        qw.orderByDesc("orders");
        UserRoleKind userRoleKind = userRoleKindService.getOne(qw, false);
        if (userRoleKind == null) {
            return -1;
        } else {
            return userRoleKind.getOrders();
        }
    }
}
